package com.adhere.system.mapper;

import com.adhere.system.pojo.RbacUser;
import com.adhere.system.pojo.vo.UserDetailVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 如果考虑使用login_name进行hash作为code字段值，则没必要设置code的唯一性，否则需要设置 Mapper 接口
 * </p>
 *
 * @author 
 * @since 2021-04-02
 */
public interface RbacUserMapper extends BaseMapper<RbacUser> {

    Page<RbacUser> getUserListByPage(Page<RbacUser> rbacUserPage, String loginName, String roleCode);

    UserDetailVo getUserDetailByUserName(String loginName);

    /**
     * 根据角色编码查询用户编码
     * @param roleCode
     * @return
     */
    @Select("select a.code from rbac_user a left join rbac_user_role b on a.code = b.user_code where b.role_code = #{roleCode}")
    List<String> getUserListByRoleCode(String roleCode);

    UserDetailVo getUserDetailByUserCode(String userCode);

    @Select("SELECT a.* FROM rbac_user a left join rbac_user_role b on a.code = b.user_code where b.role_code = 'PVMrl5DlenW' and a.is_deleted = 0 and a.is_locked = 0;")
    List<RbacUser> getUserWithAdmin();

}
